package com.ling.ling_push_player;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.ywl5320.wlmedia.surface.WlSurfaceView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PlayActivity extends AppCompatActivity {
    private String TAG = this.getClass().getSimpleName();
    @BindView(R.id.WlSurfaceView)
    com.ywl5320.wlmedia.surface.WlSurfaceView WlSurfaceView;
    private LingVideo lingVideo;
    private String url;
    public static Handler MAINACTIVITY_HANDLER = new Handler(Looper.getMainLooper());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //隐藏状态栏
        //定义全屏参数
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        //获得当前窗体对象
        Window window = PlayActivity.this.getWindow();
        //设置当前窗体为全屏显示
        window.setFlags(flag, flag);
        getWindow().getDecorView().setSystemUiVisibility(View.INVISIBLE);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_main1);
        ButterKnife.bind(this);
        url = getIntent().getStringExtra("url");
        initView();
    }

    private void initView() {
        intiData(WlSurfaceView);
    }

    private void intiData(WlSurfaceView wlSurfaceView) {
        lingVideo = new LingVideo(wlSurfaceView, this);
    }

    private void startPlay() {
        lingVideo.StartPlay(url);
        if (lingVideo.isPlay()) {
            lingVideo.getDuration();
            lingVideo.getNowClock();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        startPlay();
    }

    @Override
    protected void onStop() {
        super.onStop();
        lingVideo.StopVideo();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        lingVideo.release();
    }

    private boolean imageView_playIsChanged = false;

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.e(TAG, "dispatchTouchEvent: +DOWN");
                CLEAR_IS_MOVE = false;
                break;
            case MotionEvent.ACTION_UP:
                Log.e(TAG, "dispatchTouchEvent: +UP");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.e(TAG, "dispatchTouchEvent: +MOVE");
                CLEAR_IS_MOVE = true;
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

    private boolean CLEAR_WINDOW = false;
    private boolean CLEAR_IS_MOVE = false;

}
